package com.linsir.lin.controller.rbac;

import com.linsir.core.BaseResponse;
import com.linsir.lin.dto.AccountDTO;
import com.linsir.lin.dto.GridDTO;
import com.linsir.lin.pojo.Account;
import com.linsir.lin.service.AccountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.websocket.server.PathParam;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.text.ParseException;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping(value = "/account")
public class AccountController {



    @Autowired
    private AccountService accountService;

    /**
     * 账号列表
     * @param page
     * @param limit
     * @param searchParams
     * @return
     * @throws IllegalAccessException
     * @throws IOException
     * @throws InvocationTargetException
     */
    @RequestMapping(value = "/grid",method = {RequestMethod.POST,RequestMethod.GET})
    public GridDTO<AccountDTO> gird(String page,
                                    String limit,
                                    String searchParams) throws IllegalAccessException, IOException, InvocationTargetException {
            return accountService.grid(page,limit,searchParams);
    }

    /**
     * 添加账号
     * @param account
     * @return
     * @throws ParseException
     */
    @RequestMapping(value = "/add",method = {RequestMethod.POST})
    public BaseResponse<Boolean> doAddAccount(Account account) throws ParseException {
            return  accountService.addOrUpdate(account);
    }

    /**
     * 批量删除账号
     * @param ids
     * @return
     */
    @RequestMapping(value = "/batchDel",method = {RequestMethod.GET})
    public BaseResponse<Boolean> batchDel(String ids)
    {
            return accountService.batchDel(ids);
    }

    /**
     * 编辑或增加角色
     * @return
     */
    @RequestMapping(value = "/addRoles/{accountID}",method = {RequestMethod.POST})
    public BaseResponse<Boolean> addRoles(@RequestBody Map<String,Object> map, @PathVariable("accountID") String accountID)
    {

        return accountService.addRoles(map,Integer.parseInt(accountID));
    }

}
